import request from '@/utils/request'
// src/api/chapters.js

// 1. 创建章节
export function createChapter(data) {
  // data包含: { volume_id, title, content }
  return request({
    url: "/api/v1/chapters/create",
    method: "POST",
    data
  });
}

// 2. 删除章节
export function deleteChapter(chapterId) {
  return request({
    url: "/api/v1/chapters/delete",
    method: "POST",
    data: { chapter_id: chapterId }
  });
}

// 3. 编辑章节标题
export function editChapterTitle(chapterId, title) {
  return request({
    url: "/api/v1/chapters/edit/title",
    method: "POST",
    data: {
      chapter_id: chapterId,
      title
    }
  });
}

// 4. 编辑章节内容
export function editChapterContent(chapterId, content) {
  return request({
    url: "/api/v1/chapters/edit_content",
    method: "POST",
    data: {
      chapter_id: chapterId,
      content
    }
  });
}
export function chapterUpdate(chapter_id,title, content) {
  return request({
    url: "/api/v1/chapters/update",
    method: "POST",
    data: {
      chapter_id: chapter_id,
      title:title,
      content: content
    }
  });
}
// 5. 编辑章节编号
export function editChapterNumber(chapterId, chapterNumber) {
  return request({
    url: "/api/v1/chapters/edit_number",
    method: "POST",
    data: {
      chapter_id: chapterId,
      chapter_number: chapterNumber
    }
  });
}

// 6. 章节排序
export function sortChapters(chapterId, targetChapterId, position) {
  return request({
    url: "/api/v1/chapters/sort",
    method: "POST",
    data: {
      chapter_id: chapterId,
      target_chapter_id: targetChapterId,
      position
    }
  });
}

// 7. 获取章节内容
export function getChapterContent(chapterId) {
  return request({
    url: "/api/v1/chapters/content",
    method: "POST",
    data: { chapter_id: chapterId }
  });
}

// 8. 获取章节列表
export function getChapterList(volumeId) {
  return request({
    url: "/api/v1/chapters/list",
    method: "POST",
    data: { volume_id: volumeId }
  });
}
